package com.itheima.springbootwebtlias.service.impl;

import com.itheima.springbootwebtlias.mapper.ClazzMapper;
import com.itheima.springbootwebtlias.mapper.EmpMapper;
import com.itheima.springbootwebtlias.mapper.StudentMapper;
import com.itheima.springbootwebtlias.service.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Slf4j
@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    EmpMapper empMapper;

    @Autowired
    ClazzMapper clazzMapper;

    @Autowired
    StudentMapper studentMapper;
    //员工职位统计
    @Override
    public Map jobCount() {
        //1.调用持久层EmpMapper,统计职位信息
        List<Map> jobList = empMapper.jobCount();

        //2.处理查询结果
        Map map = new HashMap();
        map.put("jobList",jobList.stream().map(item -> item.get("name")).collect(Collectors.toList()));
        map.put("dataList",jobList.stream().map(item -> item.get("value")).collect(Collectors.toList()));

        //3.返回结果
        return map;
    }

    //员工性别统计
    @Override
    public List<Map> genderCount() {
        //调用持久层EmpMapper,统计性别信息
        return empMapper.genderCount();
    }

    //学员学历统计
    @Override
    public List<Map> studentDegreeData() {
        return studentMapper.studentDegreeData();
    }

    //班级人数统计
    @Override
    public Map studentCountData() {
       List<Map> clazzList = studentMapper.stundetCountData();
       Map map = new HashMap<>();
       map.put("clazzList",clazzList.stream().map(item -> item.get("name")).collect(Collectors.toList()));
       map.put("dataList",clazzList.stream().map(item -> item.get("value")).collect(Collectors.toList()));
       return map;
    }

}
